/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Request, Response } from 'express';
import { responseSuccess, ResponseItem } from './utils';
import type { TableListItem } from '@/pages/OperatorManagement/types/SuspiciousInnCheck';
import Mock from 'mockjs';
import dayjs from 'dayjs';

function getList(req: Request, res: Response, u: string, tableList: Array<any>) {
  let realUrl = u;
  if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
    realUrl = req.url;
  }
  const { page = 1, pageSize = 10 } = req.body;
  const params = req.body;
  let dataSource = [...tableList].slice(
    ((page as number) - 1) * (pageSize as number),
    (page as number) * (pageSize as number),
  );

  const result: ResponseItem = {
    code: 0,
    msg: '',
    data: {
      data: dataSource,
      total: tableList.length.toString(),
      page: parseInt(`${params.page}`, 10).toString() || '1',
      pageSize,
    },
  };

  return res.json(result);
}

const generateCheckList = (page: number, pageSize: number) => {
  const tableList: TableListItem[] = [];
  for (let i = 0; i < pageSize; i += 1) {
    const index = (page - 1) * 10 + i;
    tableList.push({
      id: `${index}`,
      inn_name: `驿站账号名称${index}`,
      inn_location: `驿站账号地址${index}`,
      cm_id: `驿站账号${index}`,
      phone: `1527777888${index}`,
      sen_words: '驿站,号,地址',
      register_time: `${dayjs().format('YYYY-MM-DDTHH:mm:ss')}`,
      update_time: `${dayjs().format('YYYY-MM-DDTHH:mm:ss')}`,
    });
  }
  return tableList;
};

const tableList = generateCheckList(1, 100);

export default {
  'POST /Inn/interceptUsers ': (req: Request, res: Response, u: string) =>
    getList(req, res, u, tableList),
  'POST /Inn/updateInterceptUser ': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /Inn/getApplicationInfo': (req: Request, res: Response) => {
    const data = Mock.mock({
      inn_info: {
        'id|1-10000': 10000,
        inn_name: 'XXX驿站',
        cm_id: '2222',
        full_location: 'xxx省xxx市xxx区',
        phone: '13312341234',
        concat_phone: '18812341234',
        register_time: '2021-02-09 13:12:12',
        apply_time: '2021-02-09 13:12:12',
        'is_auth_realname|0-1': 1,
        'business_audit_status|1-3': 3,
        brand_cn: '申通',
      },
      inn_stat: {
        today_in_num: '10',
        today_out_num: '11',
        today_back_num: '12',
        storage_num: '13',
        yesterday_in_num: '14',
        yesterday_out_num: '15',
        yesterday_back_num: '16',
        out_rate_day_1: '20.3%',
        out_rate_day_3: '50.2%',
        out_rate_day_7: '99.3%',
      },
      option_record: [
        '2020-01-01 12:12 修改名称为 XXXX驿站',
        '2020-01-01 12:12 开通中通驿站代收',
        '2020-01-01 12:12 开通圆通驿站代收',
        '2020-01-01 12:12 开通圆通驿站代收',
        '2020-01-01 12:12 修改联系电话为13312341234',
        '2020-01-01 12:12 修改联系电话为13312341235',
        '2020-01-01 12:12 完善驿站信息',
        '2020-01-01 12:12 注册',
      ],
      is_option: true,
    });
    const result: ResponseItem = {
      code: 0,
      msg: 'success',
      data: data,
    };
    return res.json(result);
  },
};
